{block name="main"}
<!-- page -->
<div class="mb-20">
    <a href="{:__URL('ADDONS_MAINupdateChannelGrade')}" class="btn btn-primary"><i class="icon icon-add1"></i> 添加等级</a>
</div>
<table class="table v-table table-auto-center">
    <thead>
    <tr>
        <th>等级名称</th>
        <th>进货折扣</th>
        <th>升级条件</th>
        <th>降级条件</th>
        <th>权重</th>
        <th class="col-md-2 pr-14 operationLeft">操作</th>
    </tr>
    </thead>
    <tbody id="list">

    </tbody>
</table>
<input type="hidden" id="page_index" value="">
<nav aria-label="Page navigation" class="clearfix">
    <ul id="page" class="pagination pull-right"></ul>
</nav>

<!-- page end -->
{/block}
{block name="script"}
<script>
    require(['util'],function(util){
        util.initPage(getList);
        function getList(page_index){
            $("#page_index").val(page_index);
            /*var level = $("#level").val();
            var search_text = $("#search_text").val();
            var iphone = $("#iphone").val();
            var status = $("#status").val();*/
            $.ajax({
                type : "post",
                url : '{$channelGradeList}',
                async : true,
                data : {
                    "page_index" :page_index
                    // , "search_text" : search_text, "level_id" : level, "is_global_agent" : status,"iphone":iphone
                },
                success : function(data) {
                    var html = '';
                    // console.log(data);return;
                    if (data["data"].length>0) {
                        for (var i = 0; i < data["data"].length; i++) {
                            // console.log(data['data'][i]["channel_grade_name"]);
                            html += '<tr>';
                            // html += '<img src="' + data['data'][i]["user_headimg"] + '" width="50" height="50">';
                            html += '<td><span class="block">' + data['data'][i]["channel_grade_name"] + '</span></td>';
                            html += '<td><span class="block">' + data['data'][i]["purchase_discount"] + '</span>';
                            html += '<td><span class="block">' + data['data'][i]["upgrade_str"] + '</span></td>';
                            html += '<td><span class="block">' + data['data'][i]["downgrade_str"] + '</span></td>';
                            html += '<td ><span class="block">' +data["data"][i]["weight"] +'</span></td>';

                            if(data["data"][i]['weight'] == 1){
                                html += '<td class="operationLeft fs-0">' +
                                    '<a class="btn-operation" href="'+__URL('ADDONS_MAINupdateChannelGrade&channel_grade_id='+ data['data'][i]['channel_grade_id']) +'">编辑</a>'
                                html += '</td>';
                            }else{
                                html += '<td class="operationLeft fs-0"><a class="btn-operation" href="'+__URL('ADDONS_MAINupdateChannelGrade&channel_grade_id='+ data['data'][i]['channel_grade_id']) +'">编辑</a><a href="javascript:void(0);" class="btn-operation text-red1 isexamine delete" data-type=-1 data-id="'+ data["data"][i]['channel_grade_id']+'">删除</a>'
                            }
                            html += '</tr>';
                        }
                    } else {
                        html += '<tr><td class="h-200" colspan="6">暂无符合条件的数据记录</td></tr>';
                    }
                    $('#page').paginator('option', {
                        totalCounts: data['total_count']  // 动态修改总数
                    });
                    $("#list").html(html);
                }
            });
        }
        $('.search').on('click',function(){
            util.initPage(getList);
        });
        $('body').on('click','.save',function(){
            var status = $(this).data('type');
            var uid = $(this).data('id');
            if(status==-1){
                util.alert('确定审核不通过？',function(){
                    $.ajax({
                        type : "post",
                        url : "{$setGlobalAgentStatusUrl}",
                        data:{'uid':uid,'status':status},
                        async : true,
                        success : function(data) {
                            if(data["code"] > 0 ){
                                util.message(data["message"], 'success', getList($("#page_index").val()));
                            }else{
                                util.message(data["message"], 'danger', getList($("#page_index").val()));
                            }
                        }
                    });
                })
            }else{
                util.alert('确定审核通过？',function(){
                    $.ajax({
                        type : "post",
                        url : "{$setGlobalAgentStatusUrl}",
                        data:{'uid':uid,'status':status},
                        async : true,
                        success : function(data) {
                            if(data["code"] > 0 ){
                                util.message(data["message"], 'success', getList($("#page_index").val()));
                            }else{
                                util.message(data["message"], 'danger', getList($("#page_index").val()));
                            }
                        }
                    });
                })
            }
        })
        $('body').on('click','.delete',function(){
            channel_grade_id = $(this).data('id');
            $.ajax({
                type : "post",
                url : "{$deletaChannelGrade}",
                data:{'channel_grade_id':channel_grade_id},
                async : true,
                success : function(data) {
                    if(data["code"] > 0 ){
                        util.message(data["message"], 'success', getList($("#page_index").val()));
                    }else{
                        util.message(data["message"], 'danger', getList($("#page_index").val()));
                    }
                }
            });
        })
    })
</script>
{/block}
